//
// Created by Administrator on 2021/8/9.
//
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <climits>
#include <stack>

using namespace std;
class MyQueue {
private:
    stack<int>input;
    stack<int>output;
public:
    /** Initialize your data structure here. */
    MyQueue() {
    }

    /** Push element x to the back of queue. */
    void push(int x)    {
        input.push(x);
    }

    /** Removes the element from in front of queue and returns that element. */
    int pop() {
        if (output.empty()){
            // 把输入栈里的数转进来
           transfer();
        }
        auto ans = output.top();
        output.pop();
        return ans;
    }

    /** Get the front element. */
    int peek() {
        if (output.empty())
            transfer();
        return output.top();
    }

    /** Returns whether the queue is empty. */
    bool empty() {
        return input.empty() and output.empty();
    }
    void transfer(){
        // 把输入栈的数据转到输出栈
        while (!input.empty()){
            output.push(input.top());
            input.pop();
        }
    }
};

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue* obj = new MyQueue();
 * obj->push(x);
 * int param_2 = obj->pop();
 * int param_3 = obj->peek();
 * bool param_4 = obj->empty();
 */
int main() {
    auto obj = new MyQueue;
    obj->push(1);
    obj->push(2);
    cout << obj->pop()<<endl;
    cout << obj->peek()<<endl;
    cout << obj->empty()<<endl;
    return 0;
}
